﻿<template>
  <div class="app-container">
    <div class="chart-title">档案管理</div>
    <div class="chart-content">
      <div class="filter-title">
        <el-form label-position="right">
          <el-form-item>
            <el-input v-model="listQuery.order_no"
                      style="width: 160px; height:32px;"
                      class="filter-item"
                      :placeholder="$t('order.no')"
                      @keyup.enter.native="handleFilter"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="listQuery.supplier_name"
                      style="width: 160px; height:32px;"
                      class="filter-item"
                      :placeholder="$t('supplier.name')"
                      @keyup.enter.native="handleFilter"></el-input>
          </el-form-item>
          <el-form-item>
            <el-select style="width: 160px; height:32px;"
                       v-model="listQuery.status"
                       clearable
                       :placeholder="$t('public.status')">
              <el-option v-for="item in statusOptions"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <div class="search-button"
               @click="handleFilter">
            <img src="@/assets/images/bg_search@2x.png" />
          </div>
          <div class="search-button"
               @click="handleRefresh">
            <img src="@/assets/images/bg_reset@2x.png" />
          </div>
        </el-form>
      </div>
      <div class="chart-list">
        <el-table :key="tableKey"
                  v-loading="listLoading"
                  :data="list"
                  element-loading-text="拼命加载中"
                  element-loading-spinner="el-icon-loading"
                  element-loading-background="rgba(255,255,255,0.2)"
                  border
                  fit
                  highlight-current-row
                  style="width: 100%min-height:1000px">
          <el-table-column fixed="left"
                           align="center"
                           :label="$t('table.id')"
                           width="65">
            <template slot-scope="scope">
              <span>{{
                (listQuery.page - 1) * listQuery.limit + scope.$index + 1
              }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           show-overflow-tooltip
                           :label="$t('public.no')">
            <template slot-scope="scope">
              <span>{{ scope.row.order_no }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           show-overflow-tooltip
                           :label="$t('public.status')">
            <template slot-scope="scope">
              <span>{{ orderStatus(scope.row.status) }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           show-overflow-tooltip
                           :label="$t('purchase.createTime')">
            <template slot-scope="scope">
              <span>{{ scope.row.create_time }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           show-overflow-tooltip
                           :label="$t('purchase.updateTime')">
            <template slot-scope="scope">
              <span>{{ scope.row.update_time }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           show-overflow-tooltip
                           :label="$t('supplier.name')">
            <template slot-scope="scope">
              <span>{{ scope.row.supplier_name }}</span>
            </template>
          </el-table-column>

          <el-table-column align="center"
                           show-overflow-tooltip
                           :label="$t('goods.number_1')">
            <template slot-scope="scope">
              <span>{{ scope.row.number }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           show-overflow-tooltip
                           :label="$t('goods.money')">
            <template slot-scope="scope">
              <span>{{ scope.row.money }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center"
                           :label="$t('table.actions')"
                           class-name="small-padding fixed-width"
                           fixed="right">
            <template slot-scope="scope">
              <div class="read-img"
                   @click="handleRead(scope.row)">
                <img src="@/assets/images/read@2x.png" />
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-container">
        <el-pagination background
                       :current-page="listQuery.page"
                       :page-sizes="[10, 20, 30, 50]"
                       :page-size="listQuery.limit"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="total"
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"></el-pagination>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import dropDownSelect from "@/views/select/dropDownSelect"; // 分页选择控件
import { getToken } from "@/utils/auth";
export default {
  name: "Itoc",
  components: {
    "drop-down-select": dropDownSelect
  },
  data() {
    return {
      showSearchItem: false,
      tableKey: 0,
      list: null,
      total: null,
      listLoading: true,
      statusOptions: [{
        value: 1,
        label: '待审核'
      }, {
        value: 2,
        label: '待发货'
      }, {
        value: 3,
        label: '待收货'
      }, {
        value: 4,
        label: '已完成'
      }],
      listQuery: {
        page: 1,
        limit: 20,
        order_no: "",
        supplier_name: "",
        status: ""
      },
      dialogStatus: "",
      textMap: {
        edit: "编辑",
        create: "添加",
        review: "审核",
        read: "查看"
      },
      pageSize: 20,
      optionProps: {
        value: 'id',
        label: 'name'
      }
    };
  },
  created() {
    const token = getToken()
    if (token && !this.$store.state.socket.loginTransition && !this.$store.state.socket.loginAccount) {
      this.tokenLogin(token)
    }
    this.getList();
  },
  methods: {
    tokenLogin(token) {
      const path = {
        app: "wxadmin",
        api: "api_wxadmin_admin_keepLogin",
        version: "1.0",
        type: 2,
        data: {
          token: token
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        this.socketData(res);
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    handleRefresh() {
      this.listQuery = {
        page: 1,
        limit: 20,
        order_no: "",
        supplier_name: "",
        status: ""
      };
      this.getList();
    },
    getList() {
      this.listLoading = true;
      const data = {
        rows: this.listQuery.limit,
        page: this.listQuery.page,
        order_no: this.listQuery.order_no ? this.listQuery.order_no : "",
        supplier_name: this.listQuery.supplier_name ? this.listQuery.supplier_name : "",
        status: this.listQuery.status ? this.listQuery.status : ""
      };
      // 获取终端列表
      const path = {
        app: "equipment",
        api: "api_equipment_index_orderList",
        version: "1.0",
        data: data
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    handleRead(row) {
      sessionStorage.setItem('stockMess', JSON.stringify(row));
      this.$router.push({
        path: '/terminal-data/purchase-order-details'
      })
    },
    socketData(res) {
      if (res !== '{"type":"ping"}') {
        const resj = JSON.parse(res);
        if (resj.code === -1) {
          this.$message.error(resj.message);
        } else {
          if (resj.api === "api_wxadmin_admin_keepLogin") {
            this.$store.dispatch("loginTransition", true);
            this.socketApi.sendCache(res => {
              this.socketData(res);
            })
          } else if (resj.api === "api_equipment_index_orderList") {
            this.total = resj.count;
            this.list = resj.data;
            this.listLoading = false;
            console.log('this.list', this.list)
          }
        }
      }
    }
  }
};
</script>
